import { InventoryService } from './../service/inventoryService';
import { config } from './../domain/old_ldc/server/modules/config';
import { WebException } from './webException';
import { Response, ServiceConfig, Guid, route } from "../common";
var webconfig = require("../../webconfig").webconfig;

export class SystemController {
    private inventorySvr: InventoryService;
    constructor() {
        this.inventorySvr = ServiceConfig.Current.GetService<InventoryService>("inventoryService");
    }

    toString(){
        return "SystemController";
    }

    @route({ method: 'get', path: '/api/system/getStoreId' })
    async getStoreId(ctx, next) {
        ctx.response.body = Response.ok("获取店铺id成功", { storeId: webconfig.storeId });
        await next();

    }

    @route({ method: "get", path: "/api/system/isOnline" })
    async isOnline(ctx, next) {
        ctx.response.body = Response.ok("online", {});
        await next();
    }

    @route({ method: "get", path: "/api/system/getServerTime" })
    async getServerTime(ctx, next) {
        const result = { serverTime: new Date().getTime() }
        ctx.response.body = Response.ok("online", result);
        await next();
    }

    @route({ method: "get", path: "/api/system/storeInfo/:storeId" })
    async getStoreInfo(ctx, next) {
        let storeId = ctx.params.storeId;
        let result = await this.inventorySvr.GetStoreInfo(storeId);
        ctx.response.body = Response.ok("获取成功", result);
    }
}
